import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);
const state = { // 全局管理的数据存储
	isLogin: '0',
	ser: null,
	token: uni.getStorageSync('token') ? uni.getStorageSync('token') : '', // token
	userIn: uni.getStorageSync('userIn') ? uni.getStorageSync('userIn') : '', // token
	keywords:uni.getStorageSync('keywords') || '[]'
};
export default new Vuex.Store({
	state,
	mutations: {
		$_setToken(state,value) { // 设置存储token
			state.token = value;
			uni.setStorageSync('token', value);
		},
		$_removeStorage(state,value) { // 删除token
			uni.removeStorageSync('token');
		},
		userIn(state, value){
			state.userIn=value
			uni.setStorageSync('userIn', value);
		},
		removeuserIn(state,value) { // 删除token
			uni.removeStorageSync('userIn');
		},
		saveSearchHistory(state,value){
			state.keywords = value;
			uni.setStorageSync('keywords',value)
		},
		removeSearchHistory(state,value){
			uni.removeStorageSync('keywords')
		}
	},
	actions: {},
	getters: {
		getStorage(state) { // 获取本地存储的登录信息
			if (!state.token) {
				state.token = uni.getStorageSync("token")
			}
			return state.token
		},
		getuserInfo(state) { // 获取本地存储的登录信息
			if (!state.userIn) {
				state.userIn = uni.getStorageSync("userIn")
			}
			return state.userIn
		}
	}
})
